<div class="fm-content">
  <!-- 最上面标题栏 -->
  <div class="title">
    <i nz-icon [type]="'desktop'"></i>
    &nbsp;&nbsp;租户管理
  </div>
  <!-- 内容 -->
  <div class="work">

    <!-- 查询框 -->
    <div class="top">
      <input nz-input placeholder="名称" class="fm-input first-input" [(ngModel)]="fs.queryObject['name:like']" />
      <nz-select [(ngModel)]="fs.queryObject['type']" class="fm-input" (nzOpenChange)="typeDic.load('0')" name="stype"
        [nzPlaceHolder]="'性质'">
        <nz-option *ngFor="let option of typeDic.datas" [nzLabel]="option.display" [nzValue]="option.id">
        </nz-option>
        <nz-option *ngIf="typeDic.isLoading" nzDisabled nzCustomContent>
          <i nz-icon type="loading" class="loading-icon"></i>加载中...
        </nz-option>
      </nz-select>
      <nz-button-group>
        <button nz-button nzType="primary" (click)="fs.loadData(true)">查询</button>
        <button nz-button (click)="fs.resetQueryObject() && fs.loadData(true)">重置</button>
      </nz-button-group>
      <div class="tool-right">
        <nz-button-group>
          <button nz-button [nzType]="'primary'" (click)="fs.addRow()">新增</button>
          <button nz-button (click)="fs.editRow()">编辑</button>
          <button nz-popconfirm nzTitle="确认删除选择项?" (nzOnConfirm)="fs.delEntitys()" nzPlacement="bottomRight"
            nz-button>删除</button>
        </nz-button-group>
      </div>
    </div>

    <!-- 右则样表单主体 -->
    <div class="work-content">
      <div class="table">
        <nz-table nzSize="middle" nzShowSizeChanger [nzPageSizeOptions]='[ 10, 15, 20, 30, 40, 50 ]'
          [nzFrontPagination]="false" [nzData]="fs.datas" [nzLoading]="fs.isLoading || fs.isDeleing"
          [nzTotal]="fs.rowsCount" [(nzPageIndex)]="fs.pageIndex" [(nzPageSize)]="fs.pageSize"
          (nzPageIndexChange)="fs.loadData()" (nzPageSizeChange)="fs.loadData(true)">
          <thead (nzSortChange)="fs.sort($event)" nzSingleSort>
            <tr>
              <th nzShowCheckbox [(nzChecked)]="fs.allChecked" [nzIndeterminate]="fs.indeterminate"
                (nzCheckedChange)="fs.checkAll($event)"></th>
              <th>名称</th>
              <th>规模(人)</th>
              <th>性质</th>
              <th>联系人</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of fs.datas">
              <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="fs.refreshCheckStatus()">
              </td>
              <td><span (click)="fs.editRow(data)" class="form-edit">{{data.name}}</span></td>
              <td>{{data.size}}</td>
              <td>{{data.typeName}}</td>
              <td>{{data.contacts}}</td>
              <td><a nz-popconfirm nzTitle="初始化会重置该用户下的管理员信息，确认初始化？" (nzOnConfirm)="initTenantUser(data)"
                  nzPlacement="bottomRight">租户初始化</a></td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>

    <nz-modal nzWidth='830' nzTitle="编辑" [nzMaskClosable]='false' [nzFooter]="null" [(nzVisible)]="fs.isEditVisible"
      (nzOnCancel)="fs.closeEdit()">
      <form nz-form [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">名称</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="sname.invalid?'error':'success'" nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.name" name="sname" required #sname="ngModel" />
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">帐号</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="accounts.invalid?'error':'success'"
                nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.accounts" name="accounts" required #accounts="ngModel" />
              </nz-form-control>
            </nz-form-item>
          </div>

        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">所在城市</nz-form-label>
              <nz-form-control>
                <nz-select style="width: 190px;margin-right: 3px;" [(ngModel)]="fs.er.sheng" name="sheng"
                  (nzOpenChange)="adminDic.loadOne()" (ngModelChange)="adminDic.clearOne(fs.er, 'shi', 'xian')"
                  [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of adminDic.one" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="adminDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                </nz-select>
                <nz-select style="width: 190px;margin-right: 3px;" [(ngModel)]="fs.er.shi" name="shi"
                  (nzOpenChange)="adminDic.loadTwo(fs.er.sheng)" (ngModelChange)="adminDic.clearTwo(fs.er, 'xian')"
                  [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of adminDic.two" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="adminDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                </nz-select>
                <nz-select style="width: 192px;" [(ngModel)]="fs.er.xian" name="xian"
                  (nzOpenChange)="adminDic.loadThree(fs.er.shi)" [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of adminDic.three" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="adminDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                </nz-select>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">规模</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="isize.invalid?'error':'success'" nzHasFeedback>
                <nz-input-number [(ngModel)]="fs.er.size" name="isize" required #isize="ngModel" [nzMin]="1"
                  [nzMax]="100" [nzStep]="1" class="form-control">
                </nz-input-number>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">性质</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="stype.invalid?'error':'success'" nzHasFeedback>
                <nz-select [(ngModel)]="fs.er.type" (nzOpenChange)="typeDic.load('0')" name="stype" required
                  #stype="ngModel" [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of typeDic.datas" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="typeDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                  <span *ngIf="!typeDic.isLoaded">
                    <nz-option [nzLabel]="fs.er.typeName" [nzValue]="fs.er.type"></nz-option>
                  </span>
                </nz-select>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">联系人</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="contacts.invalid?'error':'success'"
                nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.contacts" name="contacts" required #contacts="ngModel" />
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">联系电话</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="tel.invalid?'error':'success'" nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.tel" name="tel" required #tel="ngModel" />
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">邮箱</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.email" name="email" />
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" class="form-button-align">
            <button nz-button nzType="default" (click)="fs.closeEdit()" class="form-button">取消</button>
            <button nz-button nzType="primary"
              [disabled]='sname.invalid || accounts.invalid || isize.invalid || stype.invalid || contacts.invalid || tel.invalid'
              (click)="fs.save()" [nzLoading]="fs.isSaveing">保存</button>
          </div>
        </div>
      </form>
    </nz-modal>
  </div>
</div>
